package com.example.activetest;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

public class ProductMq {
    public static void main(String[] args) throws JMSException {
//            建立mq的连接
        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(ActiveMQConnectionFactory.DEFAULT_USER, ActiveMQConnectionFactory.DEFAULT_PASSWORD, "tcp://127.0.0.1:61616");
//            创立连接
        Connection createConnection = connectionFactory.createConnection();
//            启动连接
        createConnection.start();
//            创立会话工厂
        Session session = createConnection.createSession(Boolean.FALSE, Session.AUTO_ACKNOWLEDGE);
//          创建队列
        Destination destination = session.createQueue("test_queue");
        MessageProducer producer = session.createProducer(destination);
//          不持久化操作
        producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
        for (int i =10;i<=20;i++){
            System.out.println("生产者：" +i);
            sendMessage(session,producer,"生产者"+i);

        }
        System.out.println("成功");
    }
    public static void sendMessage(Session session,MessageProducer producer,String string) throws JMSException {
        TextMessage textMessage = session.createTextMessage("hello MQ" + string);
        producer.send(textMessage);
    }


}
